package com.credithc.customers.dataservice.mapper.DLR;

import com.credithc.customers.dataservice.po.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface DlrMapper {
    @Select("select customer_no customerNo ,pre_customer_no preCustomerNo from qm_user where user_id = #{id}")
    CustomerNoPo getByUserId(@Param("id") String id);
    @Select("select product_name productName,id,increment_id incrementId ,create_time creatTime ,update_time updateTime\n" +
            "from qm_product_manager  where increment_id<= #{incrementId} and increment_id > #{incrementId} -1000 ORDER BY increment_id desc ")
    List<SystemProductPo> queryDlrProduct(@Param("incrementId")String incrementId);
    @Select("select MAX(increment_id)  from qm_product_manager")
    Long queryProductMaxId();
    @Select("select increment_id id,sts, user_id userId,sub_product_id productId,period,amount,capital_effect_date capitalEffectDate ,expire_date expireDate ,sts ,increment_id incrementId\n" +
            "from qm_lend_order where increment_id<= #{incrementId} and increment_id > #{incrementId}-1000 ORDER BY increment_id desc")
    List<SystemLendPo>queryDlrLend(@Param("incrementId")String incrementId);
    @Select("select MAX(increment_id)  from qm_lend_order")
    Long queryLendMaxId();
    @Select("select customer_id customerId ,customer_no customerNo,user_type userType ,increment_id incrementId,user_id userId ,update_time updateTime,customer_open_time creatTime\n" +
            "from qm_user where increment_id <= #{incrementId} and increment_id > #{incrementId}-1000 ORDER BY qm_user.increment_id desc")
    List<SystemUserPo>queryDlrQmUser(@Param("incrementId")String incrementId );
    @Select("select MAX(increment_id)  from qm_user")
    Long queryUserMaxId();
    @Select("select count(*) from qm_product_manager  where increment_id< #{incrementId}")
    int queryProCount(int incrementId);
    @Select("select count(*) from qm_lend_order where increment_id< #{incrementId}")
    int queryLendCount(int incrementId);
    @Select("select count(*) from qm_user where increment_id < #{incrementId} ")
    int queryUserCount(int incrementId);
    @Select("select  sts ,customer_no customerNo ,qm_user_card.user_id userId,qm_user_card.increment_id incrementId ,qm_user_card.bank_card_no customerId ,qm_user_card.update_time updateTime,qm_user_card.create_time creatTime " +
            " from qm_user_card LEFT JOIN qm_user on qm_user.user_id =qm_user_card.user_id " +
            " where qm_user_card.increment_id <= #{toString} and  qm_user_card.increment_id > #{toString} - 1000 ORDER BY qm_user.increment_id desc")
    List<SystemUserPo> queryDlrQmBankCard(@Param("toString") String toString );
    @Select("select MAX(increment_id)  from qm_user_card")
    Long queryUserBankMaxId();
    @Select("<script> " +
            "SELECT qm_user.customer_no customerNo,qm_user_info.card_type cardType ,qm_user_info.real_name name ,qm_user_info.id_card_no cardNo from qm_user_info LEFT JOIN qm_user on qm_user_info.user_id =qm_user.user_id\n" +
            " where qm_user.customer_no in " +
            " <foreach collection='list' index='index' item='item' open='(' separator=',' close=')'> " +
            " #{item} " +
            " </foreach> " +
            " </script>")
    List<ServiceSystemUserInfo> queryCardInfoByUserIds(List<String> ids);



}
